package com.carambatv.android.ui.sliding;

import java.io.InputStream;

import org.apache.http.HttpResponse;

import android.content.Context;
import android.os.Bundle;

import com.carambatv.android.utils.YtubeProcessor;
import com.the111min.android.api.HttpUtils;
import com.the111min.android.api.Request;
import com.the111min.android.api.ResponseHandler;

public class VideoResponceHandler extends ResponseHandler {

	@Override
	public boolean handleResponse(Context context, HttpResponse response, Request request, Bundle result) throws Exception {
		InputStream inputStream = HttpUtils.readHttpResponseStream(response);
		YtubeProcessor ytubeProccesor = new YtubeProcessor();
		String type = request.getTemporaryData().getString(VideoFragment.TYPE);
		int numer = request.getTemporaryData().getInt(MyApiHelper.ITEM_NUMBER);
		int count = ytubeProccesor.processInternal(context.getContentResolver(), inputStream, type, numer == 1);
		result.putInt(YtubeProcessor.TOTAL_RESULTS, count);
		return true;
	}
}
